const { ipcRenderer } = require('electron')
const button = document.querySelector('.button')
let timer = null
button.addEventListener('click', () => {
  clearInterval(timer)
  ipcRenderer.send('close-warning')
})

ipcRenderer.on('warning-data', (evt, data, timeInterval) => {
  console.log(data, timeInterval)
  const plate1 = document.querySelector('.left i')
  const plate2 = document.querySelector('.right i')
  console.log(plate1, plate2)
  plate1.innerText = data.composition1
  plate2.innerText = data.composition2

  // 倒计时自动关闭弹窗
  timeInterval = Number(timeInterval || 10) || 10
  timer = setInterval(() => {
    button.innerHTML = `确定(${timeInterval}s)`
    if (timeInterval <= 0) {
      clearInterval(timer)
      ipcRenderer.send('close-warning')
      return
    }
    timeInterval--
  }, 1000)
})
